<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>rename_song (MusicBank)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File music_bank.rb, line 188</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rename_song</span>(<span class="ruby-identifier">song</span>, <span class="ruby-identifier">format</span>, <span class="ruby-identifier">deep</span>=<span class="ruby-value">1</span>)
    <span class="ruby-identifier">song</span> = <span class="ruby-identifier">get_song</span>(<span class="ruby-identifier">song</span>);
    <span class="ruby-identifier">new_song</span> = <span class="ruby-identifier">apply_format</span>(<span class="ruby-identifier">song</span>, <span class="ruby-identifier">format</span>.<span class="ruby-identifier">dup</span>);
    <span class="ruby-comment cmt">#puts &quot;\n43(rename_song): song = #{song.inspect}; new = #{new_song.inspect}; format = #{format.inspect}&quot;;</span>
    <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@songs</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">new_song</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">song</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">new_song</span>
      <span class="ruby-identifier">new_song</span> = <span class="ruby-ivar">@rename_format</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">&quot;(%s)&quot;</span>, <span class="ruby-identifier">new_song</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-ivar">@exts</span>, <span class="ruby-value str">&quot;&quot;</span>)).<span class="ruby-identifier">sub</span>(<span class="ruby-value str">&quot;(%n)&quot;</span>, <span class="ruby-identifier">deep</span>.<span class="ruby-identifier">to_s</span>);
      <span class="ruby-comment cmt">#puts &quot;46(if): ....redirect(#{song.inspect}, #{new_song.inspect})&quot;</span>
      <span class="ruby-identifier">rename_song</span>(<span class="ruby-identifier">song</span>, <span class="ruby-identifier">new_song</span>, (<span class="ruby-identifier">deep</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>));
    <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@songs</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">song</span>)
      <span class="ruby-ivar">@songs</span>[<span class="ruby-ivar">@songs</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">song</span>)] = <span class="ruby-identifier">new_song</span>;
      <span class="ruby-comment cmt">#puts @songs.inspect</span>
      <span class="ruby-identifier">chdir</span>;
      <span class="ruby-constant">File</span>.<span class="ruby-identifier">rename</span>(<span class="ruby-identifier">song</span>, <span class="ruby-identifier">new_song</span>);
      <span class="ruby-comment cmt">#puts &quot;51: Ok, renamed to #{new_song.inspect}&quot;;</span>
    <span class="ruby-keyword kw">end</span>
    <span class="ruby-identifier">new_song</span>;
  <span class="ruby-keyword kw">end</span></pre>
</body>
</html>